﻿namespace WMS6.SQLServerDAL
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Data.Common;
    using System.Data.SqlClient;
    using WMS6.Common;
    using WMS6.DataEntity;
    using WMS6.DBUtility;
    using WMS6.IDAL;
    using WMS6.QueryEntity;

    public class WaveDA : IWaveDA
    {
        private string ALLOW_CONSOLIDATION = "@ALLOW_CONSOLIDATION";
        private string AUTO_BATCH = "@AUTO_BATCH";
        private string BATCH_FLAG = "@BATCH_FLAG";
        private string CASE_PICK_DISPATCH_METHOD = "@CASE_PICK_DISPATCH_METHOD";
        private string CREATED_BY = "@CREATED_BY";
        private string DESCR = "@DESCR";
        private string EXTERNAL_WAVE_ID = "@EXTERNAL_WAVE_ID";
        private string LABELS_PER_CASE = "@LABELS_PER_CASE";
        private string LABELS_PER_PALLET = "@LABELS_PER_PALLET";
        private string PALLET_PICK_DISPATCH_METHOD = "@PALLET_PICK_DISPATCH_METHOD";
        private string PIECE_PICK_DISPATCH_METHOD = "@PIECE_PICK_DISPATCH_METHOD";
        private string SQL_CHECK_WAVE_ID_UNIQUE = " SELECT COUNT(1) FROM @_@WAVE WHERE WAVE_ID = @WAVE_ID ";
        private string SQL_DELETE_WAVE = " DELETE FROM @_@WAVE WHERE WAVE_ID = @WAVE_ID ";
        private string SQL_INSERT_WAVE = " INSERT INTO @_@WAVE ( WH_ID, WAVE_ID, WAVE_TYPE, DESCR, PALLET_PICK_DISPATCH_METHOD, CASE_PICK_DISPATCH_METHOD, PIECE_PICK_DISPATCH_METHOD, LABELS_PER_CASE, LABELS_PER_PALLET, STATUS, BATCH_FLAG, AUTO_BATCH, ALLOW_CONSOLIDATION, EXTERNAL_WAVE_ID, CREATED_BY, CREATED_DATE, UPDATED_BY, UPDATED_DATE) VALUES ( @WH_ID, @WAVE_ID, @WAVE_TYPE, @DESCR, @PALLET_PICK_DISPATCH_METHOD, @CASE_PICK_DISPATCH_METHOD, @PIECE_PICK_DISPATCH_METHOD, @LABELS_PER_CASE, @LABELS_PER_PALLET, @STATUS, @BATCH_FLAG, @AUTO_BATCH, @ALLOW_CONSOLIDATION, @EXTERNAL_WAVE_ID, @CREATED_BY, GETDATE(), @UPDATED_BY, GETDATE() )  ";
        private string SQL_SELECT_ALL_WAVE = " SELECT  W.ROWID, W.WH_ID, W.WAVE_ID, W.WAVE_TYPE, W.DESCR, W.PALLET_PICK_DISPATCH_METHOD, W.CASE_PICK_DISPATCH_METHOD, W.PIECE_PICK_DISPATCH_METHOD, W.LABELS_PER_CASE, W.LABELS_PER_PALLET, W.STATUS, W.BATCH_FLAG, W.AUTO_BATCH, W.ALLOW_CONSOLIDATION, W.EXTERNAL_WAVE_ID, W.TS, W.CREATED_BY, W.CREATED_DATE, W.UPDATED_BY, W.UPDATED_DATE,T.[TEXT] AS STATUSD  FROM  @_@WAVE W    LEFT JOIN @_@SYS_CODE_DETAIL SCD ON SCD.SYS_CODE = W.STATUS AND SCD.SYS_CODE_TYPE = 'WaveStatus'    LEFT JOIN sysadm.TRANSLATION T ON 'WaveStatus.'+W.STATUS = T.ITEM_ID   AND  T.ITEM_TYPE = 'SYS_CODE_DETAIL' AND T.LANG+'-'+T.COUNTRY = @LANGUAGE ";
        private string SQL_SELECT_WAVE = " SELECT  W.ROWID, W.WH_ID, W.WAVE_ID, W.WAVE_TYPE, W.DESCR, W.PALLET_PICK_DISPATCH_METHOD, W.CASE_PICK_DISPATCH_METHOD, W.PIECE_PICK_DISPATCH_METHOD, W.LABELS_PER_CASE, W.LABELS_PER_PALLET, W.STATUS, W.BATCH_FLAG, W.AUTO_BATCH, W.ALLOW_CONSOLIDATION, W.EXTERNAL_WAVE_ID, W.TS, W.CREATED_BY, W.CREATED_DATE, W.UPDATED_BY, W.UPDATED_DATE FROM  @_@WAVE W ";
        private string SQL_UPDATE_STATUS = " UPDATE @_@WAVE SET STATUS=@STATUS, UPDATED_BY = @UPDATED_BY, UPDATED_DATE = GETDATE() WHERE WAVE_ID = @WAVE_ID  ";
        private string SQL_UPDATE_WAVE = " UPDATE @_@WAVE SET WH_ID = @WH_ID, WAVE_TYPE = @WAVE_TYPE, DESCR = @DESCR, PALLET_PICK_DISPATCH_METHOD = @PALLET_PICK_DISPATCH_METHOD, CASE_PICK_DISPATCH_METHOD = @CASE_PICK_DISPATCH_METHOD, PIECE_PICK_DISPATCH_METHOD = @PIECE_PICK_DISPATCH_METHOD, LABELS_PER_CASE = @LABELS_PER_CASE, LABELS_PER_PALLET = @LABELS_PER_PALLET, STATUS = @STATUS, BATCH_FLAG = @BATCH_FLAG, AUTO_BATCH = @AUTO_BATCH, ALLOW_CONSOLIDATION = @ALLOW_CONSOLIDATION, EXTERNAL_WAVE_ID = @EXTERNAL_WAVE_ID, UPDATED_BY = @UPDATED_BY, UPDATED_DATE = GETDATE() WHERE WAVE_ID = @WAVE_ID  ";
        private string STATUS = "@STATUS";
        private string TS = "@TS";
        private string UPDATED_BY = "@UPDATED_BY";
        private string WAVE_ID = "@WAVE_ID";
        private string WAVE_TYPE = "@WAVE_TYPE";
        private string WH_ID = "@WH_ID";

        public bool CheckWaveIDUnique(string waveID, string whLoginID)
        {
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@WAVE_ID", waveID) };
            return (DBHelper.ExecuteScalar(CommandType.Text, this.SQL_CHECK_WAVE_ID_UNIQUE.Replace("@_@", whLoginID), paras).ToString() == "1");
        }

        public bool CheckWaveIDUnique(DataBase dataBase, DbTransaction tran, string waveID, string whLoginID)
        {
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@WAVE_ID", waveID) };
            return (dataBase.ExecuteScalar(tran, CommandType.Text, this.SQL_CHECK_WAVE_ID_UNIQUE.Replace("@_@", whLoginID), paras).ToString() == "1");
        }

        public int DeleteWave(List<string> waveID, string whLoginID)
        {
            int result = 0;
            DataBase dataBase = new DataBase();
            DbConnection conn = dataBase.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                for (int j = 0; j < waveID.Count; j++)
                {
                    SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@WAVE_ID", waveID[j]) };
                    result += dataBase.ExecuteNonQuery(tran, CommandType.Text, this.SQL_DELETE_WAVE.Replace("@_@", whLoginID), paras);
                }
                tran.Commit();
            }
            catch (SqlException sqlEx)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return result;
        }

        public int DeleteWave(DataBase dataBase, DbTransaction tran, List<string> waveID, string whLoginID)
        {
            int result = 0;
            try
            {
                for (int j = 0; j < waveID.Count; j++)
                {
                    SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@WAVE_ID", waveID[j]) };
                    result += dataBase.ExecuteNonQuery(tran, CommandType.Text, this.SQL_DELETE_WAVE.Replace("@_@", whLoginID), paras);
                }
            }
            catch (SqlException sqlEx)
            {
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            return result;
        }

        public DataSet GetAllWave(string whLoginID, PubParasInfo pubParasInfo)
        {
            string sql = this.SQL_SELECT_ALL_WAVE.Replace("@_@", whLoginID);
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@LANGUAGE", pubParasInfo.UserLanguage) };
            return DBHelper.ExecuteDataSet(CommandType.Text, sql, paras);
        }

        public DataSet GetAllWave(DataBase dataBase, DbTransaction tran, string whLoginID, PubParasInfo pubParasInfo)
        {
            string sql = this.SQL_SELECT_ALL_WAVE.Replace("@_@", whLoginID);
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@LANGUAGE", pubParasInfo.UserLanguage) };
            return dataBase.ExecuteDataSet(tran, CommandType.Text, sql, paras);
        }

        public string GetOrderIDsByWaveID(string waveID, string whLoginID, PubParasInfo pubParasInfo)
        {
            string orderIDs = string.Empty;
            string strSql = "SELECT ORDER_ID FROM @_@WAVE_DETAIL WHERE WAVE_ID = '" + waveID + "'";
            DataSet ds = DBHelper.ExecuteDataSet(CommandType.Text, strSql.Replace("@_@", whLoginID));
            if (((ds != null) && (ds.Tables.Count > 0)) && (ds.Tables[0].Rows.Count > 0))
            {
                for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
                {
                    orderIDs = orderIDs + (string.IsNullOrEmpty(orderIDs) ? "" : ",") + ds.Tables[0].Rows[i]["ORDER_ID"].ToString();
                }
            }
            return orderIDs;
        }

        public DataSet GetOrdersByOrderSelection(string SqlWhere, string whLoginID, PubParasInfo pubParasInfo)
        {
            string strSql = " SELECT DISTINCT A.ORDER_ID,A.STATUS,A.OWNER_ID,A.PRIORITY,A.TYPE,A.CONSIGNEE_ID,A.ORDER_DATE,A.REQUESTED_SHIP_DATE,A.DOOR,A.ROUTE,A.STOP FROM @_@ORDERS A LEFT JOIN @_@ORDER_DETAIL B ON A.ORDER_ID = B.ORDER_ID WHERE A.BATCH_FLAG = 'N' AND A.STATUS = 'NEW' ".Replace("@_@", whLoginID);
            return DBHelper.ExecuteDataSet(CommandType.Text, strSql + SqlWhere);
        }

        public WaveInfo GetWaveByID(string waveID, string whLoginID, PubParasInfo pubParasInfo)
        {
            string sql = this.SQL_SELECT_ALL_WAVE.Replace("@_@", whLoginID) + " WHERE WAVE_ID = @WAVE_ID  ";
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@WAVE_ID", waveID), new SqlParameter("@LANGUAGE", pubParasInfo.UserLanguage) };
            WaveInfo waveInfo = null;
            using (IDataReader reader = DBHelper.ExecuteReader(CommandType.Text, sql, paras))
            {
                if (reader.Read())
                {
                    waveInfo = new WaveInfo((reader["ROWID"].ToString() != "") ? int.Parse(reader["ROWID"].ToString()) : 0, reader["WH_ID"].ToString(), reader["WAVE_ID"].ToString(), reader["WAVE_TYPE"].ToString(), reader["DESCR"].ToString(), reader["PALLET_PICK_DISPATCH_METHOD"].ToString(), reader["CASE_PICK_DISPATCH_METHOD"].ToString(), reader["PIECE_PICK_DISPATCH_METHOD"].ToString(), (reader["LABELS_PER_CASE"].ToString() != "") ? int.Parse(reader["LABELS_PER_CASE"].ToString()) : 0, (reader["LABELS_PER_PALLET"].ToString() != "") ? int.Parse(reader["LABELS_PER_PALLET"].ToString()) : 0, reader["STATUS"].ToString(), reader["BATCH_FLAG"].ToString(), reader["AUTO_BATCH"].ToString(), reader["ALLOW_CONSOLIDATION"].ToString(), reader["EXTERNAL_WAVE_ID"].ToString(), (byte[]) reader["TS"], reader["CREATED_BY"].ToString(), (reader["CREATED_DATE"].ToString() != "") ? DateTime.Parse(reader["CREATED_DATE"].ToString()) : new DateTime(), reader["UPDATED_BY"].ToString(), (reader["UPDATED_DATE"].ToString() != "") ? DateTime.Parse(reader["UPDATED_DATE"].ToString()) : new DateTime(), reader["STATUSD"].ToString());
                }
            }
            return waveInfo;
        }

        public WaveInfo GetWaveByID(DataBase dataBase, DbTransaction tran, string waveID, string whLoginID, PubParasInfo pubParasInfo)
        {
            string sql = this.SQL_SELECT_ALL_WAVE.Replace("@_@", whLoginID) + " WHERE WAVE_ID = @WAVE_ID  ";
            SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@WAVE_ID", waveID), new SqlParameter("@LANGUAGE", pubParasInfo.UserLanguage) };
            WaveInfo waveInfo = null;
            IDataReader reader = dataBase.ExecuteReader(tran, CommandType.Text, sql, paras);
            if (reader.Read())
            {
                waveInfo = new WaveInfo((reader["ROWID"].ToString() != "") ? int.Parse(reader["ROWID"].ToString()) : 0, reader["WH_ID"].ToString(), reader["WAVE_ID"].ToString(), reader["WAVE_TYPE"].ToString(), reader["DESCR"].ToString(), reader["PALLET_PICK_DISPATCH_METHOD"].ToString(), reader["CASE_PICK_DISPATCH_METHOD"].ToString(), reader["PIECE_PICK_DISPATCH_METHOD"].ToString(), (reader["LABELS_PER_CASE"].ToString() != "") ? int.Parse(reader["LABELS_PER_CASE"].ToString()) : 0, (reader["LABELS_PER_PALLET"].ToString() != "") ? int.Parse(reader["LABELS_PER_PALLET"].ToString()) : 0, reader["STATUS"].ToString(), reader["BATCH_FLAG"].ToString(), reader["AUTO_BATCH"].ToString(), reader["ALLOW_CONSOLIDATION"].ToString(), reader["EXTERNAL_WAVE_ID"].ToString(), (byte[]) reader["TS"], reader["CREATED_BY"].ToString(), (reader["CREATED_DATE"].ToString() != "") ? DateTime.Parse(reader["CREATED_DATE"].ToString()) : new DateTime(), reader["UPDATED_BY"].ToString(), (reader["UPDATED_DATE"].ToString() != "") ? DateTime.Parse(reader["UPDATED_DATE"].ToString()) : new DateTime(), reader["STATUSD"].ToString());
            }
            if (!reader.IsClosed)
            {
                reader.Close();
            }
            return waveInfo;
        }

        public DataSet GetWaveByQueryList(List<string> sqlWhere, WaveQueryEntity waveQuery, string whLoginID)
        {
            string temp = this.SQL_SELECT_WAVE.Replace("@_@", whLoginID);
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                if (i == 0)
                {
                    temp = temp + " WHERE " + sqlWhere[i].ToString();
                }
                else
                {
                    temp = temp + " AND " + sqlWhere[i].ToString();
                }
            }
            if (!waveQuery.IsGetAll)
            {
                temp = PagingHelper.GetPagingSQL(temp, waveQuery.CurrentPage, waveQuery.PageSize, waveQuery.SortField, waveQuery.SortDirection);
            }
            return DBHelper.ExecuteDataSet(CommandType.Text, temp);
        }

        public DataSet GetWaveByQueryList(List<string> sqlWhere, WaveQueryEntity waveQuery, string whLoginID, PubParasInfo pubParasInfo)
        {
            string temp = this.SQL_SELECT_ALL_WAVE.Replace("@_@", whLoginID);
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                if (i == 0)
                {
                    temp = temp + " WHERE " + sqlWhere[i].ToString();
                }
                else
                {
                    temp = temp + " AND " + sqlWhere[i].ToString();
                }
            }
            if (!waveQuery.IsGetAll)
            {
                temp = PagingHelper.GetPagingSQL(temp, waveQuery.CurrentPage, waveQuery.PageSize, waveQuery.SortField, waveQuery.SortDirection);
            }
            temp = temp.Replace("@LANGUAGE", "''" + pubParasInfo.UserLanguage + "''");
            return DBHelper.ExecuteDataSet(CommandType.Text, temp);
        }

        public DataSet GetWaveByQueryList(DataBase dataBase, DbTransaction tran, List<string> sqlWhere, WaveQueryEntity waveQuery, string whLoginID, PubParasInfo pubParasInfo)
        {
            string temp = this.SQL_SELECT_ALL_WAVE.Replace("@_@", whLoginID);
            for (int i = 0; i < sqlWhere.Count; i++)
            {
                if (i == 0)
                {
                    temp = temp + " WHERE " + sqlWhere[i].ToString();
                }
                else
                {
                    temp = temp + " AND " + sqlWhere[i].ToString();
                }
            }
            if (!waveQuery.IsGetAll)
            {
                temp = PagingHelper.GetPagingSQL(temp, waveQuery.CurrentPage, waveQuery.PageSize, waveQuery.SortField, waveQuery.SortDirection);
            }
            temp = temp.Replace("@LANGUAGE", "''" + pubParasInfo.UserLanguage + "''");
            return dataBase.ExecuteDataSet(tran, CommandType.Text, temp);
        }

        public int InsertWave(WaveInfo waveInfo, string whLoginID)
        {
            int result = 0;
            DataBase db = new DataBase();
            DbConnection conn = db.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                waveInfo.WhID = whLoginID.Substring(0, whLoginID.Length - 1);
                SqlParameter[] paras = this.Set_Wave_Parameters(waveInfo);
                if (paras != null)
                {
                    result += db.ExecuteNonQuery(tran, CommandType.Text, this.SQL_INSERT_WAVE.Replace("@_@", whLoginID), paras);
                }
                tran.Commit();
            }
            catch (SqlException sqlEx)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return result;
        }

        public int InsertWave(DataBase dataBase, DbTransaction tran, WaveInfo waveInfo, string whLoginID)
        {
            int result = 0;
            try
            {
                waveInfo.WhID = whLoginID.Substring(0, whLoginID.Length - 1);
                SqlParameter[] paras = this.Set_Wave_Parameters(waveInfo);
                if (paras != null)
                {
                    result += dataBase.ExecuteNonQuery(tran, CommandType.Text, this.SQL_INSERT_WAVE.Replace("@_@", whLoginID), paras);
                }
            }
            catch (SqlException sqlEx)
            {
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            return result;
        }

        private SqlParameter[] Set_Wave_Parameters(WaveInfo waveInfo)
        {
            SqlParameter[] paramArray = new SqlParameter[] { new SqlParameter(this.WH_ID, SqlDbType.VarChar, 30), new SqlParameter(this.WAVE_ID, SqlDbType.VarChar, 20), new SqlParameter(this.WAVE_TYPE, SqlDbType.VarChar, 20), new SqlParameter(this.DESCR, SqlDbType.VarChar, 100), new SqlParameter(this.PALLET_PICK_DISPATCH_METHOD, SqlDbType.VarChar, 20), new SqlParameter(this.CASE_PICK_DISPATCH_METHOD, SqlDbType.VarChar, 20), new SqlParameter(this.PIECE_PICK_DISPATCH_METHOD, SqlDbType.VarChar, 20), new SqlParameter(this.LABELS_PER_CASE, SqlDbType.Int, 4), new SqlParameter(this.LABELS_PER_PALLET, SqlDbType.Int, 4), new SqlParameter(this.STATUS, SqlDbType.VarChar, 20), new SqlParameter(this.BATCH_FLAG, SqlDbType.VarChar, 1), new SqlParameter(this.AUTO_BATCH, SqlDbType.VarChar, 1), new SqlParameter(this.ALLOW_CONSOLIDATION, SqlDbType.VarChar, 1), new SqlParameter(this.EXTERNAL_WAVE_ID, SqlDbType.VarChar, 20), new SqlParameter(this.CREATED_BY, SqlDbType.VarChar, 20), new SqlParameter(this.UPDATED_BY, SqlDbType.VarChar, 20) };
            if (!string.IsNullOrEmpty(waveInfo.WhID))
            {
                paramArray[0].Value = waveInfo.WhID;
            }
            else
            {
                paramArray[0].Value = DBNull.Value;
            }
            paramArray[1].Value = waveInfo.WaveID;
            paramArray[2].Value = waveInfo.WaveType;
            paramArray[3].Value = waveInfo.Descr;
            paramArray[4].Value = waveInfo.PalletPickDispatchMethod;
            paramArray[5].Value = waveInfo.CasePickDispatchMethod;
            paramArray[6].Value = waveInfo.PiecePickDispatchMethod;
            paramArray[7].Value = waveInfo.LabelsPerCase;
            paramArray[8].Value = waveInfo.LabelsPerPallet;
            paramArray[9].Value = waveInfo.Status;
            paramArray[10].Value = waveInfo.BatchFlag;
            paramArray[11].Value = waveInfo.AutoBatch;
            paramArray[12].Value = waveInfo.AllowConsolidation;
            if (!string.IsNullOrEmpty(waveInfo.ExternalWaveID))
            {
                paramArray[13].Value = waveInfo.ExternalWaveID;
            }
            else
            {
                paramArray[13].Value = DBNull.Value;
            }
            paramArray[14].Value = waveInfo.CreatedBy;
            paramArray[15].Value = waveInfo.UpdatedBy;
            return paramArray;
        }

        public int UpdateWave(WaveInfo waveInfo, string whLoginID)
        {
            int result = 0;
            DataBase db = new DataBase();
            DbConnection conn = db.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                waveInfo.WhID = whLoginID.Substring(0, whLoginID.Length - 1);
                SqlParameter[] paras = this.Set_Wave_Parameters(waveInfo);
                if (paras != null)
                {
                    result += db.ExecuteNonQuery(tran, CommandType.Text, this.SQL_UPDATE_WAVE.Replace("@_@", whLoginID), paras);
                }
                tran.Commit();
            }
            catch (SqlException sqlEx)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return result;
        }

        public int UpdateWave(DataBase dataBase, DbTransaction tran, WaveInfo waveInfo, string whLoginID)
        {
            int result = 0;
            try
            {
                waveInfo.WhID = whLoginID.Substring(0, whLoginID.Length - 1);
                SqlParameter[] paras = this.Set_Wave_Parameters(waveInfo);
                if (paras != null)
                {
                    result += dataBase.ExecuteNonQuery(tran, CommandType.Text, this.SQL_UPDATE_WAVE.Replace("@_@", whLoginID), paras);
                }
            }
            catch (SqlException sqlEx)
            {
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            return result;
        }

        public int UpdateWaveStatus(string waveID, string Status, string UpdateBy, string whLoginID)
        {
            int result = 0;
            DataBase db = new DataBase();
            DbConnection conn = db.connection;
            conn.Open();
            DbTransaction tran = conn.BeginTransaction();
            try
            {
                SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@WAVE_ID", waveID), new SqlParameter("@STATUS", Status), new SqlParameter("@UPDATED_BY", UpdateBy) };
                if (paras != null)
                {
                    result += db.ExecuteNonQuery(tran, CommandType.Text, this.SQL_UPDATE_STATUS.Replace("@_@", whLoginID), paras);
                }
                tran.Commit();
            }
            catch (SqlException sqlEx)
            {
                tran.Rollback();
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            finally
            {
                conn.Close();
            }
            return result;
        }

        public int UpdateWaveStatus(DataBase dataBase, DbTransaction tran, string waveID, string Status, string UpdateBy, string whLoginID)
        {
            int result = 0;
            try
            {
                SqlParameter[] paras = new SqlParameter[] { new SqlParameter("@WAVE_ID", waveID), new SqlParameter("@STATUS", Status), new SqlParameter("@UPDATED_BY", UpdateBy) };
                if (paras != null)
                {
                    result += dataBase.ExecuteNonQuery(tran, CommandType.Text, this.SQL_UPDATE_STATUS.Replace("@_@", whLoginID), paras);
                }
            }
            catch (SqlException sqlEx)
            {
                CommonErrorHandler.ErrorHandler(sqlEx, LogType.Error);
            }
            return result;
        }
    }
}

